# include <cstdio>
# include <algorithm>
# define MAXN 12890
using namespace std;

int f[MAXN], n, m, a, b;

int main() { 
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++) { 
        scanf("%d %d", &a, &b);
        for(int j = m; j >= a; j--) { 
            f[j] = max(f[j], f[j - a] + b);
        }
    }
    printf("%d\n", f[m]);
}
